package zhongbo.java.air.airmonitor.web.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.airmonitor.model.FlightActivityDaily;
import zhongbo.java.air.airmonitor.service.IFlightActivityDailyService;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;


import java.time.LocalDate;
import java.util.List;

/**
 * 说明：
 *
 * @author 钟波dellNotebook
 * @since 2025年04月08日 星期二 03:35:26
 */
@RestController
@RequestMapping("flightActivityDaily")
@Api(tags = "每日航迹活动信息接口")
public class FlightActivityDailyController {

    private static final Logger log = LoggerFactory.getLogger(FlightActivityDailyController.class);
    @Autowired
    private IFlightActivityDailyService<FlightActivityDaily> flightActivityDailyService;

    @ApiOperation("查询当天分组统计结果")
    @GetMapping("selectDailyStats")
    public ResultVo<List<FlightActivityDaily>> selectDailyStats(String date) {
        // 如果不传, 则默认查当天的统计结果
        if (StrUtil.isBlank(date)) {
            date = DateUtil.today();
        }
        List<FlightActivityDaily> dailyList = flightActivityDailyService.selectDailyStats(date);
        return ResultVo.ok(dailyList);
    }

    @ApiOperation("查询当天航迹活动结果")
    @GetMapping("getDailyStats")
    public ResultVo<List<FlightActivityDaily>> getDailyStats(String date) {
        // 如果不传, 则默认查当天的统计结果
        if (StrUtil.isBlank(date)) {
            date = DateUtil.today();
        }
        List<FlightActivityDaily> dailyList = flightActivityDailyService.getDailyStats(date);
        return ResultVo.ok(dailyList);
    }

//    @ApiOperation("添加数据")
//    @PostMapping("insert")
    @PostMapping("add")
    @ApiOperation("添加")
    public ResultVo<FlightActivityDaily> insert(@RequestBody FlightActivityDaily flightActivityDaily) {
        FlightActivityDaily insert = flightActivityDailyService.insert(flightActivityDaily);
        return ResultVo.ok(insert);
    }

//    @ApiOperation("修改数据")
//    @PostMapping("update")
    @PostMapping("edit")
    @ApiOperation("修改")
    public ResultVo<FlightActivityDaily> update(@RequestBody FlightActivityDaily flightActivityDaily) {
        FlightActivityDaily update = flightActivityDailyService.update(flightActivityDaily);
        return ResultVo.ok(update);
    }

//    @ApiOperation("删除数据")
//    @PostMapping("delete/{id}")
    @GetMapping("delete")
    @ApiOperation("删除")
    public ResultVo<String> delete(String entityId) {
        String delete = flightActivityDailyService.deleteById(entityId);
        return ResultVo.ok(delete);
    }

//    @ApiOperation("查询数据")
//    @PostMapping("queryById/{id}")
    @GetMapping("findOne")
    @ApiOperation("查询一条")
    public ResultVo<FlightActivityDaily> query(String entityId) {
        FlightActivityDaily query = flightActivityDailyService.queryById(entityId);
        return ResultVo.ok(query);
    }

    @GetMapping("findPage")
    @ApiOperation("分页查询列表")
    ResultVo<PageVo<FlightActivityDaily>> findPage(Integer page, Integer pageSize
            , String icao, String startDate, String endDate, String keyword
            , String fields, String oderByField, Boolean orderByAsc) {
        PageVo<FlightActivityDaily> pageVo = flightActivityDailyService.findPage(page, pageSize
                , icao, startDate, endDate
                , keyword, fields, oderByField, orderByAsc);
        return ResultVo.ok(pageVo);
    }

    @ApiOperation("根据icao和date查询数据")
    @PostMapping("queryByIcaoCodeAndDate/{icaoCode}/{date}")
    public ResultVo<FlightActivityDaily> queryByIcaoCodeAndDate(@PathVariable("icaoCode") String icaoCode, @PathVariable("date") String date) {
        FlightActivityDaily flightActivityDaily = flightActivityDailyService.queryByIcaoCodeAndDate(icaoCode, date);
        return ResultVo.ok(flightActivityDaily);
    }
    // todo 今日周二待做, 标准crud接口(包括分页)
}
